<template>
  <el-form>
    <el-form-item :label="$t('profile.phone')" prop="phone">
      <el-input v-model.trim="user.phone" />
    </el-form-item>
    <el-form-item :label="$t('profile.email')" prop="email">
      <el-input v-model.trim="user.email" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submit">{{ $t('profile.updateProfile') }}</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import { updateProfile } from '@/api/user'

export default {
  props: {
    user: {
      type: Object,
      default: () => {
        return {
          userId: 0,
          phone: '',
          email: ''
        }
      }
    }
  },
  methods: {
    submit() {
      this.user.userId = this.$store.getters.id
      updateProfile(this.user).then(response => {
        const data = response.data
        if (data >= 1) {
          this.$message({
            message: 'User information has been updated successfully',
            type: 'success',
            duration: 5 * 1000
          })
        }
      })
    }
  }
}
</script>
